package com.lqian.demo03.pug;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 用Java程序列出指定目录下的所有文件或文件夹(包括子文件夹及文件)
 */
public class Demo06 {
    public static void main(String[] args) {
        List<String> paths = new ArrayList<String>();
        paths = getAllFilePaths(new File("/Users/luoqian/IdeaProjects/Java_Base/Reflection_Project/src"), paths);
        for (String path : paths) {
            System.out.println(path);
        }
    }

    private static List<String> getAllFilePaths(File filePath, List<String> filePaths) {
        File[] files = filePath.listFiles();
        if (files == null) {
            return filePaths;
        }
        for (File f : files) {
            if (f.isDirectory()) {
                filePaths.add(f.getPath());
                getAllFilePaths(f, filePaths);
            } else {
                filePaths.add(f.getPath());
            }
        }
        return filePaths;
    }

}
